package com.linzx.markdown.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.linzx.markdown.dialog.AddNoteDialog;
import com.linzx.markdown.entity.DataCenter;

public class AddMarkAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        //获取编辑器对象
        Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
        //获取选择模型
        SelectionModel selectionModel = editor.getSelectionModel();
        String text = selectionModel.getSelectedText();
        DataCenter.FILE_NAME = e.getRequiredData(CommonDataKeys.PSI_FILE).getViewProvider().getVirtualFile().getName();
        DataCenter.SELECT_TEXT = text;
        AddNoteDialog dialog = new AddNoteDialog();
        dialog.show();


    }
}
